package com.bdqn.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;

/**
 * 系统用户实体类
 */
@Data // 编译时生成自动生成Getter/Setter，toString 。。。
@NoArgsConstructor // 编译时生成自动生成无参构造函数
@AllArgsConstructor // 编译时生成自动生成全参构造函数
@TableName("`sys_user`")
public class SysUser implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.AUTO) // @TableId 表示主键，type = IdType.AUTO 表示自动增长（还可以选择雪花算法、UUID等生成策略）
    // @TableField("usr_id") // 字段映射（不按默认映射时添加）
    private Long usrId;
    @TableField("usr_name")
    private String usrName; // MyBatis-Plus默认映射规则：属性usrId -> 字段usr_id
    private String usrPassword;
    private Long usrRoleId;
    private Integer usrFlag;
    // 自定义字段，数据库表中没有
    @TableField(exist = false) // 忽略此字段
    private String roleName;

    public SysUser(String usrName, String usrPassword) {
        this.usrName = usrName;
        this.usrPassword = usrPassword;
        this.usrFlag = 1;
    }

    public SysUser(String usrName, String usrPassword, Long usrRoleId, Integer usrFlag) {
        this.usrName = usrName;
        this.usrPassword = usrPassword;
        this.usrRoleId = usrRoleId;
        this.usrFlag = usrFlag;
    }

    /*
     * 如果自己写了Getter/Setter方法，Lombok就不会自动生成
     *
     * @param usrPassword
     * @throws RuntimeException
     */
    /* public void setUsrPassword(String usrPassword) throws RuntimeException {
        if (usrPassword.length() < 6) {
            throw new RuntimeException("密码太弱！");
        }
        this.usrPassword = usrPassword;
    } */

}
